<template>
  <div class="app-container">
    <el-row type="flex" justify="center">
      <el-col :span="22">
        <el-card>
          <div slot="header" class="clearfix">
            <span>项目信息</span>
          </div>
          <!-- 项目阶段 -->
          <cardProject :projectFrom="form" :projectId="projectId" />
          <!-- <cardPhase :projectId="projectId" /> -->
        </el-card>
        <el-card>
          <!-- <div slot="header" class="clearfix">
            <span>项目阶段</span>
          </div> -->
          <!-- 项目阶段 -->
          <cardPhase :projectId="projectId" :projectName="projectName"/>
        </el-card>
        <el-card>
          <div slot="header" class="clearfix">
            <span>任务信息</span>
          </div>
          <cardTask :projectId="projectId" />
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { getProject } from "@/api/ehr/project";
import cardProject from "./cardProject";
import cardTask from "./cardTask";
import cardPhase from "./cardPhase";

export default {
  name: "Project",
  components: { cardProject, cardTask, cardPhase },
  data() {
    return {
      projectId: "",
      projectName: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 任务表格数据
      taskList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 计划类型业务字典
      workEffortTypeIdOptions: [],
      // 状态业务字典
      currentStatusIdOptions: [],
      // 项目阶段字典
      phaseOptions: [],
      // 操作标识,用于区分是新增还是修改
      updateFlag: false,
      // 操作标识,用于区分是详情
      detailFlag: false,
      // 操作标识,用于区分编辑状态
      editFlag: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: "", // 排序字段
        isAsc: "", // 升序或降序 大写的 ASC或DESC,为空代表升序
        workEffortTypeId: null,
        currentStatusId: null,
        workEffortName: null,
        estimatedStartDate: null,
        estimatedCompletionDate: null,
        actualStartDate: null,
        actualCompletionDate: null,
        revisionNumber: null,
        sequenceNum: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        workEffortName: [
          { required: true, message: "任务名称不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    // 计划类型业务字典
    this.getEnumDicts("WORK_EFFORT_TYPE").then((response) => {
      this.workEffortTypeIdOptions = response.data;
    });
    // 状态业务字典
    this.getEnumDicts("WORK_EFFORT_STATUS").then((response) => {
      this.currentStatusIdOptions = response.data;
    });
    const projectId = this.$route.params && this.$route.params.workEffortId;
    this.projectId = projectId;

    this.getProject(projectId);

  },
  methods: {
    getProject(workEffortId) {
      this.reset();
      console.info("workEffortId:" + workEffortId);
      getProject(workEffortId).then(response => {
        this.form = response.data;
        this.projectName = this.form.workEffortName;
        // console.info("getProject form:" + this.form);
        // this.title = "项目详情";

      });
    },

    workEffortTypeIdFormat(row, column) {
      let val = null;
      this.workEffortTypeIdOptions.forEach((item, index) => {
        if (row.workEffortTypeId === item.enumCode) {
          val = item.description;
        }
      });
      return val;
    },
    currentStatusIdFormat(row, column) {
      let val = null;
      this.currentStatusIdOptions.forEach((item, index) => {
        if (row.currentStatusId === item.enumCode) {
          val = item.description;
        }
      });
      return val;
    },


    // 表单重置
    reset() {
      this.form = {
        workEffortId: null,
        workEffortTypeId: null,
        currentStatusId: null,
        lastStatusUpdate: null,
        workEffortPurposeTypeId: null,
        workEffortParentId: null,
        scopeEnumId: null,
        priority: null,
        percentComplete: null,
        workEffortName: null,
        showAsEnumId: null,
        sendNotificationEmail: null,
        description: null,
        locationDesc: null,
        estimatedStartDate: null,
        estimatedCompletionDate: null,
        actualStartDate: null,
        actualCompletionDate: null,
        estimatedMilliSeconds: null,
        estimatedSetupMillis: null,
        estimateCalcMethod: null,
        actualMilliSeconds: null,
        actualSetupMillis: null,
        totalMilliSecondsAllowed: null,
        totalMoneyAllowed: null,
        moneyUomId: null,
        specialTerms: null,
        timeTransparency: null,
        universalId: null,
        sourceReferenceId: null,
        fixedAssetId: null,
        facilityId: null,
        infoUrl: null,
        recurrenceInfoId: null,
        tempExprId: null,
        runtimeDataId: null,
        noteId: null,
        serviceLoaderName: null,
        quantityToProduce: null,
        quantityProduced: null,
        quantityRejected: null,
        reservPersons: null,
        reserv2ndPPPerc: null,
        reservNthPPPerc: null,
        accommodationMapId: null,
        accommodationSpotId: null,
        revisionNumber: null,
        createdDate: null,
        createdByUserLogin: null,
        lastModifiedDate: null,
        lastModifiedByUserLogin: null,
        sequenceNum: null,
        lastUpdatedStamp: null,
        lastUpdatedTxStamp: null,
        createdStamp: null,
        createdTxStamp: null
      };
      this.resetForm("form");
    },



    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.formTask.workEffortTypeId = "task";
          if (this.formTask.workEffortId != null && this.updateFlag) {
            updateTask(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTask(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },

  }
};
</script>
